<template>
    <div style="width: 100%">
        <p><strong>失败接口</strong></p>
        <el-table :data="failList" @expand-change="handleExpandChange" :border="false" row-key="key">
            <el-table-column type="expand">
                <template #default="props">
                <div m="4">
                    <p style="margin-left: 5%">请求方法: {{ props.row.methodType }}</p>
                    <p style="margin-left: 5%">请求地址: {{ props.row.path }}</p>
                    <el-table lazy :data="props.row.errList" :border="false" style="width: 80%">
                        <el-table-column label="失败类型" prop="errorType" />
                        <el-table-column label="次数" prop="count" />
                    </el-table>
                </div>
                </template>
            </el-table-column>
            <el-table-column align="left" width="60px">
                <el-tag
                    type="danger"
                    class="mx-1"
                    effect="dark"
                    >
                    失败
                </el-tag>
            </el-table-column>
            <el-table-column label="接口" prop="infName" align="left" />
            <el-table-column label="失败次数" prop="count" align="center" />
        </el-table>
    </div>
    
</template>

<script setup>
import { isNotVoid } from "@/utils/util";

const {proxy} = getCurrentInstance();
const {infMethod} = proxy.useDict("infMethod");

const failList = ref([])
const props = defineProps({
    failMap:{
        type: Map,
        default: null
    },
})

watch(() => props.failMap, (nv, ov) => {
    console.log('props.failMap.change')
    failList.value = []
    props.failMap.forEach((value, key) => {
        const cloneValue=proxy.lsh.cloneDeep(value)
        cloneValue.key=key
        failList.value.push(cloneValue);
    });
},{ deep: true, immediate: true })


function handleExpandChange(row, expanded) {
    var arr = new Array()
    if (isNotVoid(row.timeOutCount)) {
        var timeOutCount = row.timeOutCount
        arr.push({errorType: '超时', count: timeOutCount})
    }
    if (isNotVoid(row.commonErrCount)) {
        var commonErrCount = row.commonErrCount
        arr.push({errorType: '调用错误', count: commonErrCount})
    }
    row.errList = arr
    console.log(row.errList)
    // console.log(row.errList)
}

</script>